package com.ruoyi.web.controller.douyinAuthorization;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.GroupPurchaseRedemption;
import com.ruoyi.system.service.IGroupPurchaseRedemptionService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 团购兑换设置 Controller
 *
 * @author ruoyi
 * @date 2025-05-14
 */
@Api(tags="团购兑换设置")
@RestController
@RequestMapping("/system/groupPurchaseRedemption")
public class GroupPurchaseRedemptionController extends BaseController
{
    @Autowired
    private IGroupPurchaseRedemptionService groupPurchaseRedemptionService;

    /**
     * 通过门店名称查询团购兑换设置列表
     */
    @ApiOperation("通过门店名称查询团购兑换设置列表")
    @PreAuthorize("@ss.hasPermi('system:redemption:list')")
    @GetMapping("/list")
    public TableDataInfo list(@RequestParam (required = false) String storeName)
    {
        startPage();
        List<GroupPurchaseRedemption> list = groupPurchaseRedemptionService.selectGroupPurchaseRedemptionListByName(storeName);
        return getDataTable(list);
    }

    /**
     * 导出团购兑换设置列表
     */
    @ApiOperation("导出团购兑换设置列表")
    @PreAuthorize("@ss.hasPermi('system:redemption:export')")
    @Log(title = "团购兑换设置（存储团购活动的兑换规则与配置）", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, @RequestParam (required = false) String storeName)
    {
        List<GroupPurchaseRedemption> list = groupPurchaseRedemptionService.selectGroupPurchaseRedemptionListByName(storeName);
        ExcelUtil<GroupPurchaseRedemption> util = new ExcelUtil<GroupPurchaseRedemption>(GroupPurchaseRedemption.class);
        util.exportExcel(response, list, "团购兑换设置（存储团购活动的兑换规则与配置）数据");
    }

    /**
     * 获取团购兑换设置
     */
    @ApiOperation("获取团购兑换设置")
    @PreAuthorize("@ss.hasPermi('system:redemption:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(groupPurchaseRedemptionService.selectGroupPurchaseRedemptionById(id));
    }

    /**
     * 新增团购兑换设置列表
     */
    @ApiOperation("新增团购兑换设置列表")
    @PreAuthorize("@ss.hasPermi('system:redemption:add')")
    @Log(title = "团购兑换设置（存储团购活动的兑换规则与配置）", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GroupPurchaseRedemption groupPurchaseRedemption)
    {
        return toAjax(groupPurchaseRedemptionService.insertGroupPurchaseRedemption(groupPurchaseRedemption));
    }

    /**
     * 修改团购兑换设置列表
     */
    @ApiOperation("修改团购兑换设置列表")
    @PreAuthorize("@ss.hasPermi('system:redemption:edit')")
    @Log(title = "团购兑换设置（存储团购活动的兑换规则与配置）", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GroupPurchaseRedemption groupPurchaseRedemption)
    {
        return toAjax(groupPurchaseRedemptionService.updateGroupPurchaseRedemption(groupPurchaseRedemption));
    }

    /**
     * 删除团购兑换设置列表
     */
    @ApiOperation("删除团购兑换设置列表")
    @PreAuthorize("@ss.hasPermi('system:redemption:remove')")
    @Log(title = "团购兑换设置（存储团购活动的兑换规则与配置）", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(groupPurchaseRedemptionService.deleteGroupPurchaseRedemptionByIds(ids));
    }
}
